const myChildProccess = require('child_process');
const path = require("path");
import { getPlatform } from "../func/func";
import logger from "../log/log";

let child;

const runChild = () => {
    if (getPlatform() === 'win32') {
        logger.info('Neurogin-Logger-win:child_process');
        let templateFilePath = path.join(process.cwd(), '/server/Sub/SubProcess.exe')
        try {
            child = myChildProccess.spawn(templateFilePath);
        } catch (err) {
            console.log(err);
            logger.info('Neurogin-Logger-cwd:' + JSON.stringify(err));
        }
    } else {
        console.log('not win32 sys');
    }
}

const killChild = () => {
    child ? child.kill() : '';
}

export {
    runChild,
    killChild
};